package com.device.entity;

import javax.persistence.*;
import java.util.UUID;
import static com.device.util.StringUtils.isEquals;

@Entity
@Table(name = "serial_port_configs")
public class SerialPortConfig {
    
    @Id
    @Column(name = "id")
    private UUID id;
    
    @Column(name = "device_imei", nullable = false)
    private String deviceImei;
    
    @Column(name = "baud_rate", nullable = false)
    private Integer baudRate = 9600;
    
    @Column(name = "data_bits", nullable = false)
    private Integer dataBits = 8;
    
    @Column(name = "parity", nullable = false)
    private String parity = "无校验";
    
    @Column(name = "stop_bits", nullable = false)
    private Integer stopBits = 1;
    
    @Column(name = "created_time")
    private Long createdTime;
    
    @Column(name = "updated_time")
    private Long updatedTime;
    
    // Constructors
    public SerialPortConfig() {}
    
    public SerialPortConfig(String deviceImei) {
        this.id = UUID.randomUUID();
        this.deviceImei = deviceImei;
        this.createdTime = System.currentTimeMillis();
        this.updatedTime = System.currentTimeMillis();
    }

    @Override
    public boolean equals(Object obj) {
        if (null == obj) return false;
        SerialPortConfig serialPortConfig = (SerialPortConfig) obj;
        return isEquals(this.deviceImei, serialPortConfig.getDeviceImei()) &&
                this.baudRate.equals(serialPortConfig.getBaudRate()) &&
                this.dataBits.equals(serialPortConfig.getDataBits()) &&
                isEquals(this.parity, serialPortConfig.getParity()) &&
                this.stopBits.equals(serialPortConfig.getStopBits());
    }
    
    
    // Getters and Setters
    public UUID getId() {
        return id;
    }
    
    public void setId(UUID id) {
        this.id = id;
    }
    
    public String getDeviceImei() {
        return deviceImei;
    }
    
    public void setDeviceImei(String deviceImei) {
        this.deviceImei = deviceImei;
    }
    
    public Integer getBaudRate() {
        return baudRate;
    }
    
    public void setBaudRate(Integer baudRate) {
        this.baudRate = baudRate;
    }
    
    public Integer getDataBits() {
        return dataBits;
    }
    
    public void setDataBits(Integer dataBits) {
        this.dataBits = dataBits;
    }
    
    public String getParity() {
        return parity;
    }
    
    public void setParity(String parity) {
        this.parity = parity;
    }
    
    public Integer getStopBits() {
        return stopBits;
    }
    
    public void setStopBits(Integer stopBits) {
        this.stopBits = stopBits;
    }
    
    public Long getCreatedTime() {
        return createdTime;
    }
    
    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }
    
    public Long getUpdatedTime() {
        return updatedTime;
    }
    
    public void setUpdatedTime(Long updatedTime) {
        this.updatedTime = updatedTime;
    }
} 